// pages/index/picDetail/picDetail.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imageArray: [],
    pageHeight: 0,
    thumbUrl: "",
    picUrl: "",
    index: 0,
    autoplay: false,
    indicatordots: false,
    duration: 500,
    error: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var index = options.index;
    //当前页面
    var pages = getCurrentPages();
    //上一页面
    var prevPage = pages[pages.length - 2];
    var imageObj = pages[pages.length - 2].data.imageArray[index];
    console.log(imageObj.thumbUrl);
    var width = wx.getSystemInfoSync().windowWidth * 0.96;
    var height = width * (imageObj.height / imageObj.width);
    this.setData({
      index: index,
      pageHeight: height,
      thumbUrl: imageObj.thumbUrl,
      picUrl: imageObj.picUrl,
      imageArray: pages[pages.length - 2].data.imageArray
    })



  },

  imageOnloadError(e) {
    console.log(e);
    this.setData({
      error: true
    })
  },

  imageChange() {
    this.setData({
      error: false
    })
    var index = options.index;
    var imageObj = app.globalData.imageArray[index];
    console.log(app.globalData.imageArray);
    console.log(index);
    console.log(imageObj.thumbUrl);
    var width = wx.getSystemInfoSync().windowWidth;
    var height = width * (imageObj.height / imageObj.width) + 200;
    this.setData({
      index: index,
      pageHeight: height,
      thumbUrl: imageObj.thumbUrl,
      picUrl: imageObj.picUrl,
      imageArray: app.globalData.imageArray
    })
  },

  toIdentify() {
    let picUrl = this.data.picUrl
    wx.navigateTo({
      url: `/pages/index/identify/identify?path=${picUrl}`,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})